package com.will.yuaiagent.exception;

/**
 * @author will
 * @since 2025/6/26 09:30
 */
public class ThrowUtils {
    /**
     * 如果条件为真，则抛出与特定错误代码相关的异常
     * 此方法用于在条件验证失败时提供一种统一的异常抛出方式
     *
     * @param condition 决定是否抛出异常的条件
     * @param errorCode 与异常相关联的错误代码
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition){
            throw runtimeException;
        }
    }

    public static void throwIf(boolean condition, ErrorCode errorCode) {
        throwIf(condition, new BusinessException(errorCode));
    }

    public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
        throwIf(condition, new BusinessException(errorCode, message));
    }

}
